package cn.tedu.smartos.admin.controller;

import cn.tedu.smartos.admin.pojo.dto.PointsGoodsAddParam;
import cn.tedu.smartos.admin.pojo.dto.PointsGoodsUpdateParam;
import cn.tedu.smartos.admin.pojo.vo.PointsGoodsVO;
import cn.tedu.smartos.admin.service.PointsGoodsService;
import cn.tedu.smartos.base.response.JsonResult;
import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "05.积分商品管理模块")
@Slf4j
@RestController
@RequestMapping("/api/v1/points-goods")
public class PointsGoodsController {
    @Autowired
    private PointsGoodsService pointsGoodsService;

    @ApiOperation("添加积分商品")
    @ApiOperationSupport(order = 10)
    @PostMapping("add")
    public JsonResult add(@RequestBody PointsGoodsAddParam addParam) {
        log.debug("开始处理【添加积分商品】的请求，参数：{}", addParam);
        pointsGoodsService.add(addParam);
        return JsonResult.ok();
    }

    @ApiOperation("修改积分商品")
    @ApiOperationSupport(order = 20)
    @PostMapping("update")
    public JsonResult update(@RequestBody PointsGoodsUpdateParam updateParam) {
        log.debug("开始处理【修改积分商品】的请求，参数：{}", updateParam);
        pointsGoodsService.update(updateParam);
        return JsonResult.ok();
    }

    @ApiOperation("删除积分商品")
    @ApiOperationSupport(order = 30)
    @PostMapping("delete")
    public JsonResult delete(@RequestBody List<Long> goodsIds) {
        log.debug("开始处理【删除积分商品】的请求，参数：{}", goodsIds);
        pointsGoodsService.delete(goodsIds);
        return JsonResult.ok();
    }

    @ApiOperation("积分商品列表")
    @ApiOperationSupport(order = 40)
    @GetMapping("list")
    public JsonResult list(@RequestParam(defaultValue = "1") Integer pageNum,
                           @RequestParam(defaultValue = "10") Integer pageSize) {
        log.debug("开始处理【积分商品列表】的请求，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageInfo<PointsGoodsVO> pageInfo = pointsGoodsService.list(pageNum, pageSize);
        return JsonResult.ok(pageInfo);
    }

    @ApiOperation("积分商品详情")
    @ApiOperationSupport(order = 50)
    @GetMapping("detail")
    public JsonResult detail(@RequestParam Long goodsId) {
        log.debug("开始处理【积分商品详情】的请求，参数：{}", goodsId);
        PointsGoodsVO pointsGoodsVO = pointsGoodsService.detail(goodsId);
        return JsonResult.ok(pointsGoodsVO);
    }

    @ApiOperation("切换商品状态")
    @ApiOperationSupport(order = 60)
    @PostMapping("toggle-status")
    public JsonResult toggleStatus(@RequestParam Long goodsId) {
        log.debug("开始处理【切换商品状态】的请求，参数：{}", goodsId);
        pointsGoodsService.toggleStatus(goodsId);
        return JsonResult.ok();
    }
}